export default {
  inserted(el, binding, vnode) {
    let { value } = binding;
    let permissions = [];
    if (sessionStorage.getItem("ROLE")) {
      let str = sessionStorage.getItem("ROLE");
      permissions = str.split(",");
      if (value && value instanceof Array && value.length > 0) {
        let permissionRouters = value;
        let hasPermission = permissions.some(permission => {
          return permissionRouters.includes(permission);
        });
        if (!hasPermission) {
          el.parentNode && el.parentNode.removeChild(el);
        }
      } else {
        throw new Error(`need permission!`);
      }
    } else {
      throw new Error(`need permission!`);
    }
  }
};
